package com.lyp.qczp.contoller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lyp.qczp.entity.Employee;
import com.lyp.qczp.entity.Profes;
import com.lyp.qczp.service.EmployeeService;
@CrossOrigin(origins = "*")
@RestController
public class EmployeeContoller {
	@Autowired
	private EmployeeService employeeService;
	/**
	 *增改员工
	 * @param employee
	 * @return
	 */
	@PostMapping("/saveEmployee")
	public int save(Employee employee,Profes profes) {
		System.out.println(employee);
		int save = employeeService.save(employee);
		
		return save;
	}
	@PostMapping("/updateeTypeByeId")
	public int updateeTypeByeId(Integer eType, Integer eId) {
		// TODO Auto-generated method stub
		System.out.println(eType+","+eId);
		return employeeService.updateeTypeByeId(eType, eId);
	}
	/**
	 * 根据eid删除员工
	 * @param eId
	 * @return
	 */
	@PostMapping("/deleteByIdEmployee")
	public int deleteById(Integer eId) {
		return employeeService.deleteById(eId);
	}
	/**
	 * 分页条件查询员工
	 * @param page
	 * @param rows
	 * @return
	 */
	@PostMapping("/findAllEmployee")
	public Map<String, Object> findAll(Integer page,Integer rows,Employee employee) {
		PageRequest of = PageRequest.of(page-1, rows);
		Map<String, Object> findAll = employeeService.findAll(of,employee);
		return findAll;
	}
	/**
	 * 员工登录
	 */
	@PostMapping("/login")
	public Integer login(Employee employee) {
		Employee findByeName = employeeService.findByeName(employee.getEName());
		if (employee.getEPassword().equals(findByeName.getEPassword())) {
			return 1;
		}
		return 0;
	}
	/**
	 * 查询单个员工
	 * @param eName
	 * @return
	 */
	@PostMapping("/findByeName")
	public Employee findByeName(String eName) {
		// TODO Auto-generated method stub
		Employee findByeName = employeeService.findByeName(eName);
		return findByeName;
	}
	
}
